package com.qf.controller;

import com.qf.entity.Emp;
import com.qf.entity.OrderVO;
import com.qf.service.EmpService;
import com.qf.service.OrderService;
import com.qf.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Qiao
 * @date 2025/8/8
 * @desc
 */
@RestController
@Api(tags = "emp表的增删改查")
@CrossOrigin //后端跨域问题
public class EmpController {

    @Autowired
    private EmpService empService;



    @GetMapping("/emp/{empno}")
    @ApiOperation(value = "根据Id查信息")
    public R select(@PathVariable int empno){
        Emp emp = empService.select(empno);
        if (emp == null){
            R.fail(5000,"查无此人");
        }
        return R.success(emp);
    }



    @GetMapping("/emp")
    @ApiOperation(value = "查信息")
    public R selectAll(){
        List<Emp> emp = empService.selectAll();
        return R.success(emp);
    }
    @PostMapping("/emp/add")
    @ApiOperation(value = "添加用户信息")
    private R add(@RequestBody Emp emp){
        boolean empFail = empService.add(emp);
        if (!empFail){
            return R.fail(5000,"添加失败");
        }
        return R.success();
    }

    @GetMapping("/emp/delete/{empno}")
    @ApiOperation(value = "根据id删除用户信息")

    public R delete(@PathVariable int empno){
        boolean empFail = empService.delete(empno);
        if (!empFail){
            return R.fail(5000,"删除失败");
        }
        return R.success();
    }

    @PostMapping("/emp/update/{empno}")
    @ApiOperation(value = "根据id更新用户信息")
    private R update(@PathVariable int empno, @RequestBody Emp emp){
        emp.setEmpno(empno);
        boolean empFail = empService.update(emp);
        if (!empFail){
            return R.fail(5000,"更新失败");
        }
        return R.success();
    }




}
